package com.tancire.web.controller.market;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.utils.SecurityUtils;
import com.tancire.net.domain.CrmCompanyIncomeDetail;
import com.tancire.net.domain.CrmCompanyPurse;
import com.tancire.net.domain.CrmPieChart;
import com.tancire.net.service.ICrmCompanyIncomeDetailService;
import com.tancire.net.service.ICrmCompanyPurseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 客户管理Controller
 *
 * @author 陈超
 * @date 2023-12-24
 */
@RestController
@RequestMapping("/mkt/report")
public class CrmReportMktController extends BaseController {

    @Resource
    private ICrmCompanyPurseService crmCompanyPurseService;

    @Resource
    private ICrmCompanyIncomeDetailService crmCompanyIncomeDetailService;

    /**
     * 获取企业信息
     */
    @PreAuthorize("@ss.hasPermi('company:user:union')")
    @GetMapping(value = "/info")
    public AjaxResult getCompanyInfo() {
        // 获取当前登录账号userId
        CrmCompanyPurse crmCompanyPurse = this.crmCompanyPurseService.selectCrmCompanyPurseByCompanyId(SecurityUtils.getUserId());
        return AjaxResult.success("查询成功", crmCompanyPurse);
    }

    /**
     * 获取企业信息
     */
    @PreAuthorize("@ss.hasPermi('company:user:union')")
    @GetMapping(value = "/active/list")
    public AjaxResult getAuthActiveList(CrmCompanyIncomeDetail crmCompanyIncomeDetail) {
        // 获取当前登录账号userId
        crmCompanyIncomeDetail.setCompanyId(SecurityUtils.getUserId());
        List<CrmCompanyIncomeDetail> list = this.crmCompanyIncomeDetailService.selectCompanyIncomeDetailList(crmCompanyIncomeDetail);
        List<CrmPieChart> res = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(list)) {
            for (CrmCompanyIncomeDetail item : list) {
                CrmPieChart row = new CrmPieChart();
                BeanUtil.copyProperties(item, row);
                res.add(row);
            }
        }
        return AjaxResult.success("查询成功", res);
    }




}
